package xiangya.bysj.client.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import xiangya.bysj.entity.RankDoctor;
import xiangya.bysj.service.impl.DoctorServiceImpl;
import xiangya.bysj.util.StringUtil;

@Controller
@RequestMapping(value = "/client/rank")
public class RankClientController {

	@Resource(name = "doctorService")
	private DoctorServiceImpl centService;

	
	// 返回排名JSON字符串
	@ResponseBody
	// 采用springmvc注释方式
	@RequestMapping("get")
	public Object rank(@RequestParam(value="doctorid",required=false)int doctorid){
		Map<String, Object> object = new HashMap<String,Object>();
		try{
			// 获取前十名
			List<RankDoctor> list=centService.get10Top();
			list.add(0, centService.getRankById(doctorid));
			object.put("code",StringUtil.RES_SUCCESS);
			object.put("rank",list);
		}catch(Exception exception){
			object.put("code","fail");
			exception.printStackTrace();
		}
		return object;
		
	}
	
	@RequestMapping("cent")
	@ResponseBody
	public Object cent(String doctorCode,double cent)
	{
		Map<String,Object> ret = new HashMap<String,Object>();
		try{
			
			centService.updateCent(doctorCode,cent);
			
			ret.put("status",0);
		}catch(Exception e)
		{
			ret.put("status",9999);
			e.printStackTrace();
		}
	
		return ret;
	}
	
}
